package com.ruoyi.web.controller.crm;

import com.bonuo.crm.domain.WarZone;
import com.bonuo.crm.service.WarZoneService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/crm/warZone")
@Api(tags = "战区管理")
public class WarZoneController extends BaseController {
    @Autowired
    private WarZoneService warZoneService;

    // 查询战区列表
    @GetMapping("/list")
    @ApiOperation(value = "查询战区列表",httpMethod = "GET")
    public TableDataInfo list(WarZone warZone,Integer pageNum,Integer pageSize){
        if(pageNum != null && pageSize != null){
            startPage();
        }
        List<WarZone> warZoneList = warZoneService.list(warZone);
        return getDataTable(warZoneList);
    }

    //  添加战区
    @PostMapping("/add")
    @ApiOperation(value = "添加战区",httpMethod = "POST")
    public AjaxResult add(@RequestBody WarZone warZone){
        Integer add = warZoneService.add(warZone);
        return toAjax(add);
    }

    //  修改战区
    @PutMapping("/update")
    @ApiOperation(value = "修改战区",httpMethod = "PUT")
    public AjaxResult update(@RequestBody WarZone warZone){
        Integer update = warZoneService.update(warZone);
        return toAjax(update);
    }

    //  删除战区
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除战区",httpMethod = "DELETE")
    public AjaxResult delete(@PathVariable Integer id){
        Integer delete = warZoneService.delete(id);
        return toAjax(delete);
    }

    // 导出战区
    @PostMapping("/export")
    @ApiOperation(value = "导出战区",httpMethod = "POST")
    public void export(HttpServletResponse response, WarZone warZone){
        List<WarZone> warZoneList = warZoneService.list(warZone);
        ExcelUtil<WarZone> util = new ExcelUtil<WarZone>(WarZone.class);
        util.exportExcel(response, warZoneList, "战区数据");
    }
}
